package com.mall.web.controller.goods.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.goods.model.dto.GoodsNewDto;
import com.mall.goods.model.vo.GoodsNewVo;
import com.mall.goods.service.IGoodsNewService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 新品上线Controller
 */
@RestController
@RequestMapping("/admin/goods/goodsNew")
public class AdminGoodsNewController extends BaseController
{
    @Autowired
    private IGoodsNewService goodsNewService;

    /**
     * 查询新品上线列表
     */
    @PreAuthorize("@ss.hasPermi('goods:new:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsNewDto goodsNewDto)
    {
        startPage();
        List<GoodsNewVo> list = goodsNewService.selectGoodsNewList(goodsNewDto);
        return getDataTable(list);
    }

    /**
     * 导出新品上线列表
     */
    @PreAuthorize("@ss.hasPermi('goods:new:export')")
    @Log(title = "新品上线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsNewDto goodsNewDto)
    {
        List<GoodsNewVo> list = goodsNewService.selectGoodsNewList(goodsNewDto);
        ExcelUtil<GoodsNewVo> util = new ExcelUtil<GoodsNewVo>(GoodsNewVo.class);
        util.exportExcel(response, list, "新品上线数据");
    }

    /**
     * 获取新品上线详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:new:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsNewService.selectGoodsNewById(id));
    }

    /**
     * 新增新品上线
     */
    @PreAuthorize("@ss.hasPermi('goods:new:add')")
    @Log(title = "新品上线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsNewDto goodsNewDto)
    {
        return toAjax(goodsNewService.insertGoodsNew(goodsNewDto));
    }

    /**
     * 修改新品上线
     */
    @PreAuthorize("@ss.hasPermi('goods:new:edit')")
    @Log(title = "新品上线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsNewDto goodsNewDto)
    {
        return toAjax(goodsNewService.updateGoodsNew(goodsNewDto));
    }

    /**
     * 删除新品上线
     */
    @PreAuthorize("@ss.hasPermi('goods:new:remove')")
    @Log(title = "新品上线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsNewService.deleteGoodsNewByIds(ids));
    }
}
